package cn.rentaotao.spring.websocket;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.messaging.handler.annotation.MessageMapping;
import org.springframework.messaging.handler.annotation.SendTo;
import org.springframework.messaging.simp.annotation.SubscribeMapping;
import org.springframework.stereotype.Controller;

/**
 * @author rtt
 * @date 2022/5/23 16:25
 */
// @Controller
public class MarcoController {

    private final ShoutService shoutService;

    // @Autowired
    public MarcoController(ShoutService shoutService) {
        this.shoutService = shoutService;
    }

    /**
     * /app/marco
     *
     * @param incoming
     */
    @MessageMapping("/marco")
    @SendTo("/topic/shout")
    public Shout handleShout(Shout incoming) {
        System.out.println("--- Received message: " + incoming.getMessage());

        return shoutService.get(incoming.getMessage());
    }

//    @SubscribeMapping("/marco")
//    public Shout handleSubscription() {
//        Shout shout = new Shout();
//        shout.setMessage("Polo!");
//
//        return shout;
//    }
}
